<style>
.text {
  font-size: 16px;
}

.clearfix{
  background-color: #F9F9F9;
  color: #666666;
  font-weight: bold;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
.el-card__header{
  background-color: #F9F9F9;
}
.box-card {
  width: 100%;
  margin: auto;
  margin-bottom: 10px;
}
.foot{
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  position: fixed;
  bottom: 0;
  background-color: #fff;
  width: calc(100vw - 200px);
  right: 0;
}
.app-container{
  position: relative;
}

.el-table__header-wrapper .el-checkbox {
  display: none;
}
</style>
<template>
  <div class="app-container">
    <h1>请升级vip以使用此功能......</h1>
    <el-form>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="shouquan">授权</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="tongbu">同步商品</el-button>
    </el-form>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods ,syncDyGoods} from "@/api/system/goods";
import {pddSyncPddData} from "@/api/system/pdd";
import {treeselect} from "@/api/system/category";

export default {
  name: "Goods",
  dicts: ['sys_orderbys'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 抖音商品表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        priceStart:0,
        priceEnd:999999,
        payersStart:0,
        payersEnd:999999,
        commissionStart:0,
        commissionEnd:100,
        commissionRateStart:0,
        commissionRateEnd:100,
        orderSet:"desc",
        stockStart:0,
        stockEnd:999999,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productId: [
          { required: true, message: "抖音商品id不能为空", trigger: "blur" }
        ],
      },
      categoryOptions:[],
      iszx:'0',
      sensitiveWords:""
    };
  },
  created() {
    this.getCategoryTreeselect();
    // this.getList();
  },
  methods: {
    /** 查询抖音商品列表 */
    getList() {
      this.loading = true;
      this.queryParams.categoryList = this.getCategoryAllCheckedKeys();
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productId: null,
        categoryId: null,
        categoryName: null,
        title: null,
        cover: null,
        price: null,
        status: null,
        addTime: null,
        upTime: null,
        labelIds: null,
        shopName: null,
        commentNum: null,
        commentScore: null,
        couponPrice: null,
        inStock: null,
        kolNum: null,
        sales: null,
        hasSxt: null,
        detailUrl: null,
        orderNum: null,
        firstCid: null,
        secondCid: null,
        shopId: null,
        thirdCid: null,
        isAssured: null,
        twohour: null,
        oneday: null,
        week: null,
        month: null,
        activityCosRatio: null,
        corpId: null,
        promotionStartTime: null,
        promotionEndTime: null,
        originPrice: null,
        productStock: null,
        createTime: null,
        createBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      var strings = this.sensitiveWords.split(/\r?\n/);
      this.queryParams.pageNum = 1;
      this.queryParams.sensitiveWords = strings;
      this.queryParams.iszx = this.iszx;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加抖音商品";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGoods(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改抖音商品";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除抖音商品编号为"' + ids + '"的数据项？').then(function() {
        return delGoods(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 数据同步按钮操作 */
    handleSync() {
      this.$modal.confirm('是否开始同步抖音商品吗？').then(function() {
        return syncDyGoods();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("同步成功！");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport(row) {
      const ids = row.id || this.ids;
      this.download('system/dygoods/export/'+ids, {
      }, `信息采集_${new Date().getTime()}.txt`)
    },
    /** 查询菜单树结构 */
    getCategoryTreeselect() {
      treeselect().then(response => {
        this.categoryOptions = response.data;
      });
    },
    // 所有菜单节点数据
    getCategoryAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedNodes(true);
      var data = [];
      if(checkedKeys.length>0){
        for(var i=0;i<checkedKeys.length;i++){
           data.push(checkedKeys[i].data.buId);
        }
      }
      return data;
    },
    shouquan(){
      const url = "http://27.128.175.119/prod-api/pdd/pddCallback";
      const encodedUrl = encodeURIComponent(url);
      window.location.href = "https://fuwu.pinduoduo.com/service-market/auth?response_type=code&client_id=2ba77f6df16945b6860b9fbb3b9cf8ad&redirect_uri="+encodedUrl+"&state=1";
    },
    tongbu(){
      pddSyncPddData().then(response => {
        console.log(response)
      });
    }
  }
};
</script>
